<%
# Copyright (C) 2015 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%= form_for :context_module, :url => context_url(@context, :context_context_modules_url), :html => {:id => "add_context_module_form", :style => "display: none;", :class => "form-dialog"} do |f| %>
  <div class="form-dialog-content">
    <div class="ic-Form-control form-element">
      <div class="module_name form-element">
        <label class="screenreader-only" for="context_module_name">{{#t}}Module Name{{/t}}</label>
        <%= f.text_field :name, :placeholder => t('Module Name'), :id => 'context_module_name', :class => 'ic-Input' %>
      </div>

      <div class="ic-Checkbox-group form-element">
        <div class="ic-Form-control ic-Form-control--checkbox">
          <input type="checkbox" id="unlock_module_at">
          <label class="ic-Label" for="unlock_module_at">
            {{#t}}Lock until{{/t}}
          </label>
        </div>
        <div class="unlock_module_at_details form-element">
        <label class='screenreader-only' id='unlock_at_date_label'>
              {{#t}}Unlock module on date{{/t}}
              <%= datepicker_screenreader_prompt %>
            </label>
          <%= f.text_field :unlock_at,
                             class: "datetime_field",
                             'aria-labelledby' => 'unlock_at_date_label',
                             'data-tooltip' => '',
                             :placeholder => t("Unlock At"),
                             title: accessible_date_format %>
        </div>
      </div>

      <div class="prerequisites_entry form-section border border-t">
        <%= f.label :before_viewing, :en => "Prerequisites", class: "ic-Label form-element" %>
        <div class="prerequisites_list">
          <div class="criteria_list" style="display: none;"></div>
          <div id="criterion_blank_prereq" class="criterion clearfix" style="display: none;">
            <div class="prereq-req-item">
              <span class="prereq_desc"></span>
              <div class="option"></div>
            </div>
            <div class="prereq-req-item-delete">
              <button class="delete_criterion_link dim-till-hover" aria-label="{{#t}}Delete prerequisites{{/t}}">
                <i class="icon-end standalone-icon" alt="{{#t}}remove icon{{/t}}" ></i>
              </button>
            </div>
          </div>
          <div class="add-item">
            <button class="Button Button-link add_prerequisite_link add_prerequisite_or_requirement_link" tabindex="0">
              <i class="icon-add" alt="{{#t}}add icon{{/t}}"></i>{{#t}}Add prerequisite{{/t}}
            </button>
          </div>
        </div>
      </div>

    <div class="completion_entry form-section border border-t">
      <%= f.label :module_complete_when, :en => "Requirements", class: "ic-Label form-element" %>
       <div class="ic-Form-control ic-Form-control--radio requirement-count-radio">
        <div class="ic-Radio">
        <%= f.radio_button :requirement_count, "" %>
        <%= f.label :requirement_count, t("Students must complete all of these requirements"), class: "ic-Label", value: "" %>
        </div>
        <div class="form-element require-sequential ic-Form-control ic-Form-control--checkbox">
          <%= f.check_box :require_sequential_progress, :id => "require_sequential_progress" %>
          <%= f.label :require_sequential_progress, :en => "Students must move through requirements in sequential order", :for => "require_sequential_progress", class: 'ic-Label' %>
        </div>
        <div class="ic-Radio">
          <%= f.radio_button :requirement_count, 1  %>
          <%= f.label :requirement_count, t("Student must complete one of these requirements"), class: "ic-Label", value: 1 %>
        </div>
      </div>
      <div class="no_items_message form-element" style="display: none;">
        <div class="alert alert-info">
          {{#t}}No items in module{{/t}}
        </div>
      </div>
      <div class="criteria_list" style="display: none;"></div>
      <div id="criterion_blank_req" class="criterion clearfix" style="display: none;">
        <div class="prereq-req-item">
          <span class="prereq_desc">{{#t}}Must complete{{/t}}</span>
          <div class="option"></div>
        </div>
        <div class="prereq-req-item-delete">
          <button class="delete_criterion_link dim-till-hover Button" aria-label="{{#t}}Delete requirement') %>" title="<%= t('Delete requirement{{/t}}">
            <i class="icon-end standalone-icon"  alt="{{#t}}remove icon{{/t}}"></i>
          </button>
        </div>
      </div>
      <div class="add-item">
        <button class="Button Button-link add_completion_criterion_link add_prerequisite_or_requirement_link" tabindex="0">
          <i class="icon-add"  alt="{{#t}}add icon{{/t}}"></i>{{#t}}Add requirement{{/t}}
        </button>
      </div>
    </div>

      <% if Canvas::Plugin.find!('grade_export').enabled? %>
        <div class="form-element">
          <%= f.check_box :publish_final_grade, :id => "publish_final_grade" %>
          <%= f.label :publish_final_grade, :en => "Publish final grade for the student when this module is completed", :for => "publish_final_grade" %>
        </div>
      <% end %>
    </div>
  </div>

  <div class="form-controls">
    <button type="button" class="btn cancel_button">{{#t}}Cancel{{/t}}</button>
    <button type="submit" class="btn btn-primary submit_button">{{#t}}Add Module{{/t}}</button>
    <a href="<%= context_url(@context, :context_context_modules_url) %>" style="display: none;" class="add_context_module_url">&nbsp;</a>
  </div>
<% end %>
